Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
ReferenceError: client is not defined | client.userSettings = new Collection();

i have coded a discord bot but i have a problem, when i start the bot i have this problem : "ReferenceError: client is not defined", i have downloaded requirements ect...

The client :

client.userSettings = new Collection();

My interactionCreate.js :

// Check the guide at the beginning if you don't understand paths.
const User = require("../Models/User");
const cmd = client.Commands.get(interaction.commandName);
if (cmd) {
  let user = client.userSettings.get(interaction.user.id);
  // If there is no user, create it in the Database as "newUser"
  if (!user) {
    const findUser = await User.findOne({ Id: interaction.user.id });
    if (!findUser) {
      const newUser = await User.create({ Id: interaction.user.id });
      client.userSettings.set(interaction.user.id, newUser);
      user = newUser;
    } else;
  }

  if (cmd.premium && user && !user.isPremium) {
    interaction.followUp(`You are not premium user`);
  } else {
    cmd.run({ client, interaction, args });
  }
}

My User.js :

const mongoose = require("mongoose");

// The heart of the User, here is everything saved that the User does.
// Such as Levels, Courses, Premium, Enrolled, XP, Leaderboard.
const user = mongoose.Schema({
  Id: {
    type: mongoose.SchemaTypes.String,
    required: true,
    unique: true,
  },
  isPremium: {
    type: mongoose.SchemaTypes.Boolean,
    default: false,
  },
  premium: {
    redeemedBy: {
      type: mongoose.SchemaTypes.Array,
      default: null,
    },

    redeemedAt: {
      type: mongoose.SchemaTypes.Number,
      default: null,
    },

    expiresAt: {
      type: mongoose.SchemaTypes.Number,
      default: null,
    },

    plan: {
      type: mongoose.SchemaTypes.String,
      default: null,
    },
  },
});
module.exports = mongoose.model("user", user);

Please help me i very need help pls, thanks you.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Just utilize the client that you've passed to your commad:

  if (cmd.premium && user && !user.isPremium) {
    interaction.followUp(`You are not premium user`);
  } else {
    cmd.run({ **client**, interaction, args });
  }
}

Also it'd be good to see how your command looks.

about 4 years ago · Juan Pablo Isaza Relatório

0

The issue is you do not have your client defined in your interactionCreate.js. To define it, use const client = <something> if you need help with client, read this documentation.

If you are new to DiscordJS V13, you can view the docs here

Other steps you can do to trouble shoot is to reinstall discordjs and verify that you are using node version 16 and higher.

Node: In your terminal put node -v

Discord Js Reinstall: In your terminal put npm uninstall discord.js then npm install discord.js or npm install discord.js@13.6.0

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda